Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Expand web3.js transport method wrapping to improve error reporting #6

Merged
merged 3 commits into from
Jul 18, 2017

Conversation

gnidan
Copy link
Contributor

@gnidan gnidan commented Jul 17, 2017

Ref: trufflesuite/truffle#489

Mainly,

  • Define a custom ProviderError class
  • Refactor wrapper implementation

Note on error implementation:

  • web3.js reports "Invalid JSON RPC response" in place of some kind of error indicating invalid connection. This seems to be a bug?

  • String matching seems to be the only way to interpret web3 errors (web3.js throws base JS Error, not any subclass, unfortunately)

gnidan added 2 commits July 17, 2017 17:02
- Extend from base TruffleError
- Match underlying web3.js error message against known messaging
- Use message type to define "friendly error" for failures to connect

Note:

- web3.js reports "Invalid JSON RPC response" in place of some kind of error
  indicating invalid connection. This seems to be a bug?

- String matching seems to be the only way to interpret web3 errors
  (web3.js throws base JS `Error`, not any subclass, unfortunately)

- This error class is therefore likely to be brittle
- Define transport hooks to run before / after sending
- Wrap errors with ProviderError
@gnidan gnidan requested a review from tcoulter July 17, 2017 21:14
@gnidan
Copy link
Contributor Author

gnidan commented Jul 17, 2017

@tcoulter would appreciate your thoughts on approach, as well as if you happen to see any stylistic things that I could improve. (mostly trying to sketch out an idea, added comments in hopes they'll help)

" - is properly configured in your Truffle configuration file (truffle.js)\n";
}
ProviderError.super_.call(this, message);
this.message = message;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this pattern in truffle-compile but I don't know if any of that is extraneous here.

var modified = postHook(payload, error, result);
payload = modified[0];
error = modified[1];
result = modified[2];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm taking this approach specifically to modify the error that gets thrown, but it doesn't work as nicely without being able to return multiple values.

Wondering if there's a less awkward way to do this same thing (if only we could use fancy new destructuring :)

@tcoulter tcoulter merged commit bdce4fd into release Jul 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants